//
//  WmcResolutionItemCelll.swift
//  YPWatermarkCamera
//
//  Created by Json on 2023/7/11.
//

import UIKit

class WmcResolutionItemCelll: WmcBaseTableCell {
    
    private lazy var stackView: UIStackView = {
        let stackV = UIStackView()
        stackV.axis = .vertical
        stackV.spacing = 6.0.wmc_autoHor
        stackV.distribution = .fill
        stackV.alignment = .fill
        return stackV
    }()
    
    private lazy var subTitleLabel: UILabel = {
        let label = UILabel()
        label.font = 13.wmc_scaleFont()
        label.textColor = UIColor.wmc_black65
        return label
    }()
    
    private lazy var checkView: UIImageView = {
        let imgView = UIImageView()
        imgView.image = "icon_check_22".wmc_image
        return imgView
    }()
    
    var item: WmcResolutionItem = .init()  {
        didSet {
            let resolution = item.resolution
            titleLabel.text = resolution.level.name
            subTitleLabel.text = "\(resolution.height)x\(resolution.width)，约\(resolution.memorySize)"
            checkView.isHidden = !item.isSelected
        }
    }
    
    
    // MARK: Init
    override func makeUI() {
        super.makeUI()
        let hMargin = 16.0.wmc_autoHor
        let checkWH = 22.0.wmc_autoHor
        // checkView
        contentView.addSubview(checkView)
        checkView.snp.makeConstraints { make in
            make.right.equalTo(-hMargin)
            make.width.height.equalTo(checkWH)
            make.centerY.equalToSuperview()
        }
        // stackView
        contentView.addSubview(stackView)
        stackView.snp.makeConstraints { make in
            make.left.equalTo(hMargin)
            make.right.equalTo(checkView.snp.left).offset(-hMargin)
            make.centerY.equalToSuperview()
        }
        // 标题
        titleLabel.font = 15.wmc_scaleFont(weight: .medium)
        titleLabel.textColor = UIColor.wmc_blackH1_000000
        stackView.addArrangedSubview(titleLabel)
        // 副标题
        stackView.addArrangedSubview(subTitleLabel)
        // 分割线
        contentView.addSubview(lineView)
        lineView.snp.makeConstraints { make in
            make.left.equalTo(stackView)
            make.right.equalTo(checkView)
            make.bottom.equalToSuperview()
            make.height.equalTo(0.5)
        }
    }

}
